<?php if (!defined('BASEPATH'))
exit ('No direct script access allowed');

class Alipay{
	var $CI;

	public function __construct() {
		$this->CI = & get_instance();
	}

	public function alipay($data) {
		//↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
		$alipay_config =$this->config->item("alipay_config");
		$partner		= $alipay_config['partner'];					//合作身份者ID，以2088开头的16位纯数字
		$key   			= $alipay_config['key'];	//安全检验码，以数字和字母组成的32位字符
		$seller_email	= $alipay_config['seller_email'];				//签约支付宝账号或卖家支付宝帐户

		$subject		= $data['subject'];							//产品名称
		$out_trade_no	= $data['out_trade_no'];					//请与贵网站订单系统中的唯一订单号匹配
		$total_fee		= $data['total_fee'];							//订单总金额
		$out_user		= $data['out_user'];					//商户系统中用户唯一标识、例如UID、NickName

		//以下是三个返回URL
		$notify_url		= $data['notify_url'];			//服务端获取通知地址，用户交易完成异步返回地址
		$call_back_url	= $data['call_back_url'];			//用户交易完成同步返回地址
		$merchant_url	= "";			//用户付款中途退出返回地址



		//↓↓↓↓↓↓↓↓↓↓以下参数为支付宝默认参数，禁止修改其参数值↓↓↓↓↓↓↓↓↓↓

		$Service_Create				= "alipay.wap.trade.create.direct";
		$Service_authAndExecute		= "alipay.wap.auth.authAndExecute";
		$format						= "xml";
		$sec_id						= "MD5";
		$_input_charset				= "utf-8";
		$v							= "2.0";

		// 构造要请求的参数数组，无需改动
		$pms1 = array (
						"req_data" => '<direct_trade_create_req><subject>' . $subject . '</subject><out_trade_no>' . $out_trade_no . '</out_trade_no><total_fee>' . $total_fee . "</total_fee><seller_account_name>" . $seller_email . "</seller_account_name><notify_url>" . $notify_url . "</notify_url><out_user>" . $out_user . "</out_user><merchant_url>" . $merchant_url . "</merchant_url>" . "<call_back_url>" . $call_back_url . "</call_back_url></direct_trade_create_req>",
						"service" => $Service_Create,
						"sec_id" => $sec_id,
						"partner" => $partner,
						"req_id" => date ( "Ymdhms" ),
						"format" => $format,
						"v" => $v 
		);

		$this->CI->load->helper("alipay/alipay_service");
		$alipay = new alipay_service ();
		$token = $alipay->alipay_wap_trade_create_direct ( $pms1, $key, $sec_id );


		// 构造要请求的参数数组，无需改动
		$pms2 = array (
						"req_data" => "<auth_and_execute_req><request_token>" . $token . "</request_token></auth_and_execute_req>",
						"service" => $Service_authAndExecute,
						"sec_id" => $sec_id,
						"partner" => $partner,
						"call_back_url" => $call_back_url,
						"format" => $format,
						"v" => $v 
		);

		// 调用alipay_Wap_Auth_AuthAndExecute接口方法，并重定向页面
		$alipay->alipay_Wap_Auth_AuthAndExecute ( $pms2, $key );
	}

}

/**
 *End of file 'alipay.php';
 *Location './mpay/libraries/alipay.php'
 */